package xin.codedream.codelog.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xin.codedream.codelog.dao.LogsDao;
import xin.codedream.codelog.model.entity.Logs;
import xin.codedream.codelog.service.LogsService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 日志信息业务逻辑实现
 *
 * @author NGLSL
 * @date 2018/8/5
 */
@Service
public class LogsServiceImpl implements LogsService {

    @Resource
    private LogsDao logsDao;

    /**
     * 保存日信息
     *
     * @param logs 日志信息
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveLogInfo(Logs logs) {
        logsDao.saveLogInfo(logs);
    }

    /**
     * 获取最近日志信息
     *
     * @return List<Logs>
     */
    @Override
    public List<Logs> findNewLogs() {
        return logsDao.listFiveArticleLog();
    }

    @Override
    public List<Logs> findAllLogs(Integer pageNum, Integer pageSize, String startTime, String endTime) {
        PageHelper.startPage(pageNum, pageSize, true);
        return logsDao.listAllLog(startTime, endTime);
    }

    @Override
    public boolean removeAllLog() {
        return logsDao.deleteAllLog() > 0;
    }
}
